package com.eportal.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Service;

import com.eportal.action.background.pojo.Page;
import com.eportal.base.BaseDAO;
import com.eportal.domain.AppstoreCustom;
import com.eportal.exception.NotUniqueException;
import com.eportal.service.AppStoreCustomService;

@Service("appStoreCustomService")
public class AppStoreCustomServiceImpl  implements AppStoreCustomService{
	
	private Map<String, Object> result = new HashMap<String, Object>();
	private static Logger log = Logger.getLogger(AppStoreCustomServiceImpl.class.getName());
	
	@Resource(name="dao")
	private BaseDAO dao;
	
	public HttpSession getSession() {
        return ServletActionContext.getRequest().getSession();
    }

	@Override
	public void save(AppstoreCustom bean) throws Exception {
		dao.save(bean);
		
	}

	@Override
	public AppstoreCustom getByAgtcode(String agtCode) throws NotUniqueException {
		String hql="from AppstoreCustom where agtcode='"+agtCode+"'";
		return (AppstoreCustom)dao.getUniqueFirst(hql);
		
	}

	@Override
	public Page find(String where, Page page) {

        final StringBuffer hql = new StringBuffer("select t.*,a.agtName  from t10_appstore_custom t left join t02_agtent a on t.agtcode=a.agtcode where 1=1 ");
        hql.append(where);
        String countsql = "select count(*) from (" + hql.toString() + ") bb";
        int count = dao.count(countsql);
        List<Map<String, Object>> list = dao.queryBySql("select * from (select bb.*,rownum rownum_bb from (" + hql.toString() + " order by t.sid DESC ) bb where rownum<= " + (page.getCurrentPage() * page.getPageSize()) + ")" + " where rownum_bb>" + (page.getCurrentPage() - 1) * page.getPageSize());
        return new Page(page.getCurrentPage(), page.getPageSize(), count, list);
	}

	
}
